<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no,email=no" />
		<title>退款/售后</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">退款/售后</h1>
		</header>
		
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper transparent">
			<div class="mui-scroll">
				<div id="refundList">
				</div>
			</div>
		</div>
		<div id="dcontent" class="dcontent">
			<div class="ex-item"><input id="ExpressCompanyName" type="text" placeholder="快递公司"/></div>
			<div class="ex-item"><input id="ShipOrderNumber" type="text" placeholder="快递单号"/></div>
			<div class="ex-item"><a class="custom-btn" id="submitExpress">确认提交</a></div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/delayimg.min.js"></script>
		<script src="js/app.js"></script>
		<script>
			var isnodata = false,
				page = 1,
				loadPage,
				mask;
			mui.init({
				pullRefresh : {
				    container:'#pullrefresh',
				    deceleration:0.0006,
				    up : {
					    contentrefresh : "正在加载...",
					    contentnomore:'已加载完全部',
					    callback :function(){
					      	var self=this;
					      	if (!isnodata) {
					      		page++;
						        mui.ajax(URL+'api/OrderRefund/GetRefundList?&pageNo='+page+'&pageSize=10',{
									dataType:'json',
									type:'get',
									timeout:10000,
									success:function(data){
										if(data){
						                    var html='';
									        if(data.Data.length > 0) {
									        	document.getElementById('refundList').insertAdjacentHTML('beforeend',initData(html,data));
									        	delayimg.render();
									        }else{
												isnodata = true;
											}
											self.endPullupToRefresh(isnodata);
					      					
										}
									},
									error:function(xhr,type,errorThrown){
										plus.nativeUI.toast('请求失败，请检查网络')
									}
								});
						    }else{
						    	self.endPullupToRefresh(isnodata);
						    }
				    	}
				    }
				},
				swipeBack: true
			});
			
			if (mui.os.android)
				document.getElementsByClassName('mui-scroll')[0].className='';
			
			mui.plusReady(function() {
				plus.webview.currentWebview().setStyle({scrollIndicator:'none'});
				var w=plus.nativeUI.showWaiting('',{padlock:true});
				loadPage=function(){
					mui.ajax(URL+'api/OrderRefund/GetRefundList?pageNo=1&pageSize=10',{
						dataType:'json',
						type:'get',
						timeout:10000,
						success:function(data){
							if(data.Success){
								var html='';
						        if(data.Data.length > 0) {
						            document.getElementById('refundList').innerHTML=initData(html,data);
						            delayimg.init();
						        }else{
						        	html+='<div class="empty-show"><h4>暂无售后中订单...</h4><button id="closeWv" class="mui-btn mui-btn-negative">去其他地方逛逛</button></div>';
						        	document.getElementById('pullrefresh').innerHTML=html;
						        }
						        
								w.close();
								document.getElementById('pullrefresh').className='mui-content mui-scroll-wrapper';
							}
						},
						error:function(xhr,type,errorThrown){
							w.close();
							reloadWvLoad();
						}
					});
				}
				
				loadPage();
			});
			
			function initData(html,data){
				for(var i=0;i<data.Data.length;i++){
		            html+='<div class="order-info">'+
						'<div class="item">'+
							'<div class="order-shop">'+
							'<a class="vshop-url" data-id="'+data.Data[i].Vshopid+'"><i class="iconfont icon-dianpu"></i>'+data.Data[i].ShopName+'</a>'+
							'<span class="mui-pull-right">'+data.Data[i].RefundStatus+'</span></div>'+
						'</div>';
						if(data.Data[i].RefundModeValue==1){
			            	for(var j=0;j<data.Data[i].OrderItems.length;j++){
				                html+='<div class="item showRefund" data-id="'+data.Data[i].Id+'">'+
				                    '<div class="buy-goods">'+
				                        '<a class="goods-img"><img src="images/blank.gif" data-delay="'+data.Data[i].OrderItems[j].ThumbnailsUrl+'"/></a>'+
				                        '<p><span><a>'+data.Data[i].OrderItems[j].ProductName+'</a></span></p>'+
				                    '</div>'+
				                '</div>';
			               	}
		            	}else{
		            		html+='<div class="item showRefund" data-id="'+data.Data[i].Id+'">'+
			                    '<div class="buy-goods">'+
			                        '<a class="goods-img"><img src="images/blank.gif" data-delay="'+data.Data[i].Img+'"/></a>'+
			                        '<p><span><a>'+data.Data[i].ProductName+'</a></span></p>'+
			                    '</div>'+
			                '</div>';
		            	}
			            html+='<div class="item showRefund" data-id="'+data.Data[i].Id+'">'+
			            	'<div class="item-text">'+
			                    '&nbsp;<span class="mui-pull-right order-total">交易金额：¥ '+data.Data[i].EnabledRefundAmount+' &nbsp;&nbsp; 退款金额：<em>¥ '+data.Data[i].Amount+'</em></span>'+
			            	'</div>'+
			            '</div>';
			            if(data.Data[i].SellerAuditStatusValue==2){
				            html+='<div class="item total-m item-btn">'+
				            	'<button class="mui-btn mui-btn-negative showExpress" data-id="'+data.Data[i].Id+'">快递寄回</button>'+
			            	'</div>';
		            	}
			        html+='</div>';
		       	}
				return html;
			}
			
			function reloadPage(){
				loadPage();
				isnodata = false;
				page = 1;
				mui('#pullrefresh').pullRefresh().refresh(true);
			}
			
			document.addEventListener('updateData', function() {
				reloadPage();
			});
			
			
			mui('#refundList').on('tap', '.vshop-url', function() {
				var vshopid = this.getAttribute('data-id');
				if(!vshopid){
					plus.nativeUI.toast('该店铺暂未开通微店')
				}else{
					showVshop(vshopid,'/')
				}
			});
			
			mui('#refundList').on('tap', '.showRefund', function() {
				var refundId = this.getAttribute('data-id');
				himall.openVW('order-refund-detail.html','',{refundId:refundId});
			});
			
			mui('#refundList').on('tap', '.showExpress', function() {
				var refundId = this.getAttribute('data-id'),
					dcontent=document.getElementById('dcontent'),
					ExpressCompanyName=document.getElementById('ExpressCompanyName'),
					ShipOrderNumber=document.getElementById('ShipOrderNumber');
				
				ExpressCompanyName.value=ShipOrderNumber.value='';
				if(!mask)
					mask = mui.createMask(function(){dcontent.className='dcontent';});
				mask.show();
				dcontent.className='dcontent active';
				
				mui(document).on('tap','#submitExpress',function(){
					if(ExpressCompanyName.value==''){
						plus.nativeUI.toast('请填写快递公司');
						return;
					}
					if(ExpressCompanyName.value==''){
						plus.nativeUI.toast('请填写快递单号');
						return;
					}
					var w=plus.nativeUI.showWaiting('',{padlock:true});
					mui.ajax(URL+'api/OrderRefund/PostSellerSendGoods',{
						data:JSON.stringify({
							Id:refundId,
							ExpressCompanyName:ExpressCompanyName.value,
							ShipOrderNumber:ShipOrderNumber.value,
						}),
						dataType:'json',
						contentType:'application/json',
						type:'post',
						timeout:10000,
						success:function(data){
							w.close();
							if(data.success){
								plus.nativeUI.toast(data.msg);
								mask.close();
								reloadPage();
							}else{
								plus.nativeUI.toast(data.msg);
							}
						},
						error:function(xhr,type,errorThrown){
							w.close();
							plus.nativeUI.toast('提交快递信息失败，请检查网络')
						}
					});
				});
			});
			
		</script>
	</body>

</html>